//
//  BannerData.m
//  TrainTree
//
//  Created by wanghui on 2017/9/28.
//  Copyright © 2017年 YouYeShu. All rights reserved.
//

#import "BannerData.h"
NSString *const BannerDataFilePath = @"BannerData";
NSString *const BannerDataPlist   = @"BannerData.plist";
NSString *const BannerDataPlistRootKey = @"BannerData";

@implementation BannerData
+ (BannerData *)shareBannerData
{
    static BannerData *bannerdata = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        bannerdata = [[BannerData alloc] init];
    });
    return bannerdata;

}
- (NSArray *)getBannerData
{
    return [self attribute:BannerDataPlistRootKey];
}
- (void)saveBannerData:(NSArray *)array;
{
    [self setBannerValue:array key: BannerDataPlistRootKey];
}
- (void)setBannerValue:(id)value key:(NSString *)key
{
    [self setBannerValue:value key:key sub:nil];
}

- (void)setBannerValue:(id)value key:(NSString *)key sub:(NSString *)subkey
{
    [ALCacheData set:value key:key sub:subkey file:BannerDataFilePath plist:BannerDataPlist];
}

- (void)removeSearchRecord
{
    [ALCacheData removeFile:BannerDataFilePath];
    [BannerData createBannerData];
}

- (NSArray *)attribute:(NSString *)key
{
    return [ALCacheData objectForPlistKey:key file:BannerDataFilePath plist:BannerDataPlist];
}

+ (void)createBannerData
{
    if (![ALCacheData isExists:BannerDataFilePath]) {
        [ALCacheData writeData:@{BannerDataPlistRootKey:@[]} file:BannerDataFilePath plist:BannerDataPlist];
    }
}

@end
